C-Level Extensibility > The C-level extensibility API > JSBool JS_ReportError()

 

JSBool JS_ReportError()

Description

Describes the reason for a script error. Call this function before returning JS_FALSE to give the user information about why the script failed (for example, "wrong number of arguments").

Arguments

JSContext *cx, char *error, size_t sz

cx is the opaque JSContext pointer that was passed to the JavaScript function.
error is a string containing the error message. The string is copied, so the caller should free the string when it is no longer needed. If the string size is not specified (see the sz argument, below), then the string must be null-terminated.
sz is the size of the string, in bytes. If sz is 0, then the length of the null-terminated string is computed automatically.

Returns

A Boolean value indicating success (JS_TRUE) or failure (JS_FALSE).


 
Calling a C function from JavaScript

Once you know how C-level extensibility works in Dreamweaver and the data types and functions it relies on, it's useful to walk through an example of how to build a library and call a function.

This exercise requires three files, which are included in the Extending/c_files folder inside the Dreamweaver application folder:

mm_jsapi.h is a header file that includes definitions for the data types and functions described in The C-level extensibility API.
Sample.c is an example file that defines the computeSum() function.
Sample.mak is a makefile that you can use to build Sample.c into a DLL with Microsoft Visual C++; Sample.proj is the equivalent file for building a CFM Library with Metrowerks CodeWarrior. If you are using another tool, you can create the makefile yourself.

To build the DLL in Windows:

1 In Microsoft Visual C++, choose File > Open Workspace and select Sample.mak.
2 Choose Build > Rebuild All.
When the build operation is complete, a file called Sample.dll appears in the folder containing Sample.mak (or one of its subfolders).

To build the shared library on the Macintosh:

1 Open Sample.proj in Metrowerks CodeWarrior.
2 Build the project to generate a CFM Library.
When the build operation has finished, a file called Sample appears in the folder containing Sample.proj (or in one of its subfolders).

To call the computeSum() function from the Insert Horizontal Rule object:

1 In the Configuration folder within the Dreamweaver application folder, create a folder called JSExtensions.
2 Copy Sample.dll (Windows) or Sample (Macintosh) to the JSExtensions folder.
3 In a text editor, open the file called horizontal_rule.htm that resides in the Configuration/Objects/Common folder.
4 Add the line alert(Sample.computeSum(2,2)); to the objectTag() function so that it appears as follows:
function objectTag() {
	// Return the html tag that should be inserted
	alert(Sample.computeSum(2,2));
	return "<HR>";
}
5 Save the file and restart Dreamweaver.

To execute the computeSum() function:

Choose Insert > Horizontal Rule. A dialog box containing the number 4—the result of computing the sum of 2 plus 2—appears.